<meta http-equiv="Content-Type" content="text/html;charset=utf8" />
<?php
	include_once "../init.php";
	include_once "../util/mysql_class.php";
	include_once "../smarty_inc.php";
	include_once "../util/util.php";
	
	function make_news($sql_select){
		$db =  new mysql();
		//$sql_select="select * from news_info where news_id=".$news_id;
		$query = $db->query($sql_select);
		
		$row=$db->fetch_row_array($query);
		if(!empty($row)){
			$news_file = $row["news_file"];
			$news_title = $row["news_title"];
			$news_id = $row["news_id"];
			$category_id = $row["category_id"];
			make_news_html($news_file,$news_title,$news_id,$category_id);
			$update_sql = "update news_info set picked = 2 where news_id=".$news_id;
			$db->query($update_sql);
			return 1;
		}else{
			return -1;
		}
		
		
		
	}
	
	function make_news_html($news_file,$news_title,$news_id,$category_id){
		echo "txt_file:".$news_file."<br>";
		
		$localurl = $GLOBALS ['web'] ['html'].$news_id.".html";
		echo "html_file:".$localurl."<br>";
		$news_content = myfile_get_content($news_file);
		global $smarty;
		$smarty->assign("title",$news_title);
		$smarty->assign("chpctx",$news_content);
		$smarty->assign("activeIdx",$category_id);
		$novel = $smarty->fetch('chpctx_bootstrap_1.htm');
		makehtml($localurl,$novel);
		echo "<a href='/html/".$news_id.".html'>生成新闻成功</a>";
		
	}
	
	if(@$_GET["news_id"]){
		$news_id=$_GET["news_id"];
		$sql_select="select * from news_info where news_id=".$news_id;
		make_news($sql_select);
		
	}else{
		$sql_select="select * from news_info where picked=1 limit 0,1";
		$ret = make_news($sql_select);
		if($ret>0){
			pagesleep();
		}else{
			echo "所有新闻采集完成！";
		}
	}
	
	
?>
